<template>
  <div class="order">
    <NavBar logo="edit" title="我的订单"></NavBar>
    <div class="container">
      <div class="sub-nav">
        <span :class="[currentTab.name === 'all' ? active : '']" @click="getAll"
          >全部</span
        >
        <span
          :class="[currentTab.name === 'pay' ? active : '', 'long']"
          @click="getPay"
          >待付款</span
        >
        <span
          :class="[currentTab.name === 'comment' ? active : '', 'long']"
          @click="getComment"
          >待评价</span
        >
        <span
          :class="[currentTab.name === 'refund' ? active : '']"
          @click="getRefund"
          >退款</span
        >
      </div>
      <keep-alive>
        <component
          v-bind:is="currentTab.component"
          @jump-page="goTicket"
        ></component>
      </keep-alive>
    </div>
  </div>
</template>

<script>
import NavBar from '@/components/NavBar.vue'
import All from './All'
import Pay from './Pay'
import Refund from './Refund'
import Comment from './Comment'

export default {
  data() {
    return {
      tabs: [
        {
          name: 'all',
          component: All,
        },
        {
          name: 'pay',
          component: Pay,
        },
        {
          name: 'comment',
          component: Comment,
        },
        {
          name: 'refund',
          component: Refund,
        },
      ],
      currentTab: '',
      active: 'active',
    }
  },

  components: {
    NavBar,
  },

  mounted() {
    if (this.$route.params.id !== undefined) {
      this.currentTab = this.tabs[this.$route.params.id]
    } else {
      this.currentTab = this.tabs[0]
    }
  },

  methods: {
    getAll() {
      this.currentTab = this.tabs[0]
    },
    getPay() {
      this.currentTab = this.tabs[1]
    },
    getComment() {
      this.currentTab = this.tabs[2]
    },
    getRefund() {
      this.currentTab = this.tabs[3]
    },
    goTicket() {
      this.$router.push({ name: 'myTicket' })
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  padding: 40px;
  .sub-nav {
    display: flex;
    width: 670px;
    height: 50px;
    margin-bottom: 20px;
    justify-content: space-between;

    span {
      position: relative;
      width: 100px;
      text-align: center;
      font-size: 28px;
      color: #ffffff;
      line-height: 28px;

      &.active {
        color: #f9c34a;
      }

      &.active::after {
        content: '';
        position: absolute;
        height: 6px;
        width: 2em;
        background: #f9c34a;
        transform: translateX(-100%);
        bottom: 0;
      }
      &.long::after {
        width: 3em;
      }
    }
  }
}
.wrapper {
  height: calc(100vh - 205px);
  margin-top: 28px;
  overflow: hidden;

  .w-content {
    min-height: calc(100vh - 224px);
  }
}
</style>
